-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lld][WebAssembly] Replace config-> with ctx.arg. #119835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld][WebAssembly] Replace config-> with ctx.arg. #119835
Conversation
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner
|
@llvm/pr-subscribers-lld Author: Fangrui Song (MaskRay) ChangesPatch is 87.53 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119835.diff 17 Files Affected:
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 02471950fb5196..7b56bf90af3c1c 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -48,7 +48,7 @@ ConfigWrapper config;
Ctx ctx;
void errorOrWarn(const llvm::Twine &msg) {
- if (config->noinhibitExec)
+ if (ctx.arg.noinhibitExec)
warn(msg);
else
error(msg);
@@ -268,7 +268,7 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
static void readImportFile(StringRef filename) {
if (std::optional<MemoryBufferRef> buf = readFile(filename))
for (StringRef sym : args::getLines(*buf))
- config->allowUndefinedSymbols.insert(sym);
+ ctx.arg.allowUndefinedSymbols.insert(sym);
}
// Returns slices of MB by parsing MB as an archive file.
@@ -345,7 +345,7 @@ void LinkerDriver::addFile(StringRef path) {
case file_magic::bitcode:
case file_magic::wasm_object: {
auto obj = createObjectFile(mbref, "", 0, inLib);
- if (config->isStatic && isa<SharedFile>(obj)) {
+ if (ctx.arg.isStatic && isa<SharedFile>(obj)) {
error("attempted static link of dynamic object " + path);
break;
}
@@ -364,7 +364,7 @@ void LinkerDriver::addFile(StringRef path) {
}
static std::optional<std::string> findFromSearchPaths(StringRef path) {
- for (StringRef dir : config->searchPaths)
+ for (StringRef dir : ctx.arg.searchPaths)
if (std::optional<std::string> s = findFile(dir, path))
return s;
return std::nullopt;
@@ -373,8 +373,8 @@ static std::optional<std::string> findFromSearchPaths(StringRef path) {
// This is for -l<basename>. We'll look for lib<basename>.a from
// search paths.
static std::optional<std::string> searchLibraryBaseName(StringRef name) {
- for (StringRef dir : config->searchPaths) {
- if (!config->isStatic)
+ for (StringRef dir : ctx.arg.searchPaths) {
+ if (!ctx.arg.isStatic)
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
return s;
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
@@ -408,10 +408,10 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
addFile(arg->getValue());
break;
case OPT_Bstatic:
- config->isStatic = true;
+ ctx.arg.isStatic = true;
break;
case OPT_Bdynamic:
- config->isStatic = false;
+ ctx.arg.isStatic = false;
break;
case OPT_whole_archive:
inWholeArchive = true;
@@ -527,99 +527,98 @@ getBuildId(opt::InputArgList &args) {
// Initializes Config members by the command line options.
static void readConfigs(opt::InputArgList &args) {
- config->allowMultipleDefinition =
+ ctx.arg.allowMultipleDefinition =
hasZOption(args, "muldefs") ||
args.hasFlag(OPT_allow_multiple_definition,
OPT_no_allow_multiple_definition, false);
- config->bsymbolic = args.hasArg(OPT_Bsymbolic);
- config->checkFeatures =
+ ctx.arg.bsymbolic = args.hasArg(OPT_Bsymbolic);
+ ctx.arg.checkFeatures =
args.hasFlag(OPT_check_features, OPT_no_check_features, true);
- config->compressRelocations = args.hasArg(OPT_compress_relocations);
- config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
- config->disableVerify = args.hasArg(OPT_disable_verify);
- config->emitRelocs = args.hasArg(OPT_emit_relocs);
- config->experimentalPic = args.hasArg(OPT_experimental_pic);
- config->entry = getEntry(args);
- config->exportAll = args.hasArg(OPT_export_all);
- config->exportTable = args.hasArg(OPT_export_table);
- config->growableTable = args.hasArg(OPT_growable_table);
- config->noinhibitExec = args.hasArg(OPT_noinhibit_exec);
+ ctx.arg.compressRelocations = args.hasArg(OPT_compress_relocations);
+ ctx.arg.demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
+ ctx.arg.disableVerify = args.hasArg(OPT_disable_verify);
+ ctx.arg.emitRelocs = args.hasArg(OPT_emit_relocs);
+ ctx.arg.experimentalPic = args.hasArg(OPT_experimental_pic);
+ ctx.arg.entry = getEntry(args);
+ ctx.arg.exportAll = args.hasArg(OPT_export_all);
+ ctx.arg.exportTable = args.hasArg(OPT_export_table);
+ ctx.arg.growableTable = args.hasArg(OPT_growable_table);
+ ctx.arg.noinhibitExec = args.hasArg(OPT_noinhibit_exec);
if (args.hasArg(OPT_import_memory_with_name)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
args.getLastArgValue(OPT_import_memory_with_name).split(",");
} else if (args.hasArg(OPT_import_memory)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
} else {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::optional<std::pair<llvm::StringRef, llvm::StringRef>>();
}
if (args.hasArg(OPT_export_memory_with_name)) {
- config->memoryExport =
- args.getLastArgValue(OPT_export_memory_with_name);
+ ctx.arg.memoryExport = args.getLastArgValue(OPT_export_memory_with_name);
} else if (args.hasArg(OPT_export_memory)) {
- config->memoryExport = memoryName;
+ ctx.arg.memoryExport = memoryName;
} else {
- config->memoryExport = std::optional<llvm::StringRef>();
+ ctx.arg.memoryExport = std::optional<llvm::StringRef>();
}
- config->sharedMemory = args.hasArg(OPT_shared_memory);
- config->soName = args.getLastArgValue(OPT_soname);
- config->importTable = args.hasArg(OPT_import_table);
- config->importUndefined = args.hasArg(OPT_import_undefined);
- config->ltoo = args::getInteger(args, OPT_lto_O, 2);
- if (config->ltoo > 3)
- error("invalid optimization level for LTO: " + Twine(config->ltoo));
+ ctx.arg.sharedMemory = args.hasArg(OPT_shared_memory);
+ ctx.arg.soName = args.getLastArgValue(OPT_soname);
+ ctx.arg.importTable = args.hasArg(OPT_import_table);
+ ctx.arg.importUndefined = args.hasArg(OPT_import_undefined);
+ ctx.arg.ltoo = args::getInteger(args, OPT_lto_O, 2);
+ if (ctx.arg.ltoo > 3)
+ error("invalid optimization level for LTO: " + Twine(ctx.arg.ltoo));
unsigned ltoCgo =
- args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo));
+ args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(ctx.arg.ltoo));
if (auto level = CodeGenOpt::getLevel(ltoCgo))
- config->ltoCgo = *level;
+ ctx.arg.ltoCgo = *level;
else
error("invalid codegen optimization level for LTO: " + Twine(ltoCgo));
- config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
- config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
- config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
- config->mapFile = args.getLastArgValue(OPT_Map);
- config->optimize = args::getInteger(args, OPT_O, 1);
- config->outputFile = args.getLastArgValue(OPT_o);
- config->relocatable = args.hasArg(OPT_relocatable);
- config->gcSections =
- args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !config->relocatable);
+ ctx.arg.ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
+ ctx.arg.ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
+ ctx.arg.ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+ ctx.arg.mapFile = args.getLastArgValue(OPT_Map);
+ ctx.arg.optimize = args::getInteger(args, OPT_O, 1);
+ ctx.arg.outputFile = args.getLastArgValue(OPT_o);
+ ctx.arg.relocatable = args.hasArg(OPT_relocatable);
+ ctx.arg.gcSections =
+ args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !ctx.arg.relocatable);
for (auto *arg : args.filtered(OPT_keep_section))
- config->keepSections.insert(arg->getValue());
- config->mergeDataSegments =
+ ctx.arg.keepSections.insert(arg->getValue());
+ ctx.arg.mergeDataSegments =
args.hasFlag(OPT_merge_data_segments, OPT_no_merge_data_segments,
- !config->relocatable);
- config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
- config->printGcSections =
+ !ctx.arg.relocatable);
+ ctx.arg.pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
+ ctx.arg.printGcSections =
args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
- config->saveTemps = args.hasArg(OPT_save_temps);
- config->searchPaths = args::getStrings(args, OPT_library_path);
- config->shared = args.hasArg(OPT_shared);
- config->shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
- config->stripAll = args.hasArg(OPT_strip_all);
- config->stripDebug = args.hasArg(OPT_strip_debug);
- config->stackFirst = args.hasArg(OPT_stack_first);
- config->trace = args.hasArg(OPT_trace);
- config->thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
- config->thinLTOCachePolicy = CHECK(
+ ctx.arg.saveTemps = args.hasArg(OPT_save_temps);
+ ctx.arg.searchPaths = args::getStrings(args, OPT_library_path);
+ ctx.arg.shared = args.hasArg(OPT_shared);
+ ctx.arg.shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
+ ctx.arg.stripAll = args.hasArg(OPT_strip_all);
+ ctx.arg.stripDebug = args.hasArg(OPT_strip_debug);
+ ctx.arg.stackFirst = args.hasArg(OPT_stack_first);
+ ctx.arg.trace = args.hasArg(OPT_trace);
+ ctx.arg.thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
+ ctx.arg.thinLTOCachePolicy = CHECK(
parseCachePruningPolicy(args.getLastArgValue(OPT_thinlto_cache_policy)),
"--thinlto-cache-policy: invalid cache policy");
- config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
- config->thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
+ ctx.arg.thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
+ ctx.arg.thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
+ ctx.arg.thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
- config->thinLTOObjectSuffixReplace =
+ ctx.arg.thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
+ ctx.arg.thinLTOObjectSuffixReplace =
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
- std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
- config->thinLTOPrefixReplaceNativeObject) =
+ std::tie(ctx.arg.thinLTOPrefixReplaceOld, ctx.arg.thinLTOPrefixReplaceNew,
+ ctx.arg.thinLTOPrefixReplaceNativeObject) =
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace_eq);
- if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) {
+ if (ctx.arg.thinLTOEmitIndexFiles && !ctx.arg.thinLTOIndexOnly) {
if (args.hasArg(OPT_thinlto_object_suffix_replace_eq))
error("--thinlto-object-suffix-replace is not supported with "
"--thinlto-emit-index-files");
@@ -627,45 +626,45 @@ static void readConfigs(opt::InputArgList &args) {
error("--thinlto-prefix-replace is not supported with "
"--thinlto-emit-index-files");
}
- if (!config->thinLTOPrefixReplaceNativeObject.empty() &&
- config->thinLTOIndexOnlyArg.empty()) {
+ if (!ctx.arg.thinLTOPrefixReplaceNativeObject.empty() &&
+ ctx.arg.thinLTOIndexOnlyArg.empty()) {
error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with "
"--thinlto-index-only=");
}
- config->unresolvedSymbols = getUnresolvedSymbolPolicy(args);
- config->whyExtract = args.getLastArgValue(OPT_why_extract);
+ ctx.arg.unresolvedSymbols = getUnresolvedSymbolPolicy(args);
+ ctx.arg.whyExtract = args.getLastArgValue(OPT_why_extract);
errorHandler().verbose = args.hasArg(OPT_verbose);
LLVM_DEBUG(errorHandler().verbose = true);
- config->tableBase = args::getInteger(args, OPT_table_base, 0);
- config->globalBase = args::getInteger(args, OPT_global_base, 0);
- config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
- config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
- config->maxMemory = args::getInteger(args, OPT_max_memory, 0);
- config->noGrowableMemory = args.hasArg(OPT_no_growable_memory);
- config->zStackSize =
+ ctx.arg.tableBase = args::getInteger(args, OPT_table_base, 0);
+ ctx.arg.globalBase = args::getInteger(args, OPT_global_base, 0);
+ ctx.arg.initialHeap = args::getInteger(args, OPT_initial_heap, 0);
+ ctx.arg.initialMemory = args::getInteger(args, OPT_initial_memory, 0);
+ ctx.arg.maxMemory = args::getInteger(args, OPT_max_memory, 0);
+ ctx.arg.noGrowableMemory = args.hasArg(OPT_no_growable_memory);
+ ctx.arg.zStackSize =
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
// -Bdynamic by default if -pie or -shared is specified.
- if (config->pie || config->shared)
- config->isStatic = false;
+ if (ctx.arg.pie || ctx.arg.shared)
+ ctx.arg.isStatic = false;
- if (config->maxMemory != 0 && config->noGrowableMemory) {
+ if (ctx.arg.maxMemory != 0 && ctx.arg.noGrowableMemory) {
// Erroring out here is simpler than defining precedence rules.
error("--max-memory is incompatible with --no-growable-memory");
}
// Default value of exportDynamic depends on `-shared`
- config->exportDynamic =
- args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, config->shared);
+ ctx.arg.exportDynamic =
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, ctx.arg.shared);
// Parse wasm32/64.
if (auto *arg = args.getLastArg(OPT_m)) {
StringRef s = arg->getValue();
if (s == "wasm32")
- config->is64 = false;
+ ctx.arg.is64 = false;
else if (s == "wasm64")
- config->is64 = true;
+ ctx.arg.is64 = true;
else
error("invalid target architecture: " + s);
}
@@ -679,36 +678,36 @@ static void readConfigs(opt::InputArgList &args) {
error(arg->getSpelling() + ": expected a positive integer, but got '" +
arg->getValue() + "'");
parallel::strategy = hardware_concurrency(threads);
- config->thinLTOJobs = v;
+ ctx.arg.thinLTOJobs = v;
}
if (auto *arg = args.getLastArg(OPT_thinlto_jobs))
- config->thinLTOJobs = arg->getValue();
+ ctx.arg.thinLTOJobs = arg->getValue();
if (auto *arg = args.getLastArg(OPT_features)) {
- config->features =
+ ctx.arg.features =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->features->push_back(std::string(s));
+ ctx.arg.features->push_back(std::string(s));
}
if (auto *arg = args.getLastArg(OPT_extra_features)) {
- config->extraFeatures =
+ ctx.arg.extraFeatures =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->extraFeatures->push_back(std::string(s));
+ ctx.arg.extraFeatures->push_back(std::string(s));
}
// Legacy --allow-undefined flag which is equivalent to
// --unresolve-symbols=ignore + --import-undefined
if (args.hasArg(OPT_allow_undefined)) {
- config->importUndefined = true;
- config->unresolvedSymbols = UnresolvedPolicy::Ignore;
+ ctx.arg.importUndefined = true;
+ ctx.arg.unresolvedSymbols = UnresolvedPolicy::Ignore;
}
if (args.hasArg(OPT_print_map))
- config->mapFile = "-";
+ ctx.arg.mapFile = "-";
- std::tie(config->buildId, config->buildIdVector) = getBuildId(args);
+ std::tie(ctx.arg.buildId, ctx.arg.buildIdVector) = getBuildId(args);
}
// Some Config members do not directly correspond to any particular
@@ -716,86 +715,86 @@ static void readConfigs(opt::InputArgList &args) {
// This function initialize such members. See Config.h for the details
// of these values.
static void setConfigs() {
- ctx.isPic = config->pie || config->shared;
+ ctx.isPic = ctx.arg.pie || ctx.arg.shared;
if (ctx.isPic) {
- if (config->exportTable)
+ if (ctx.arg.exportTable)
error("-shared/-pie is incompatible with --export-table");
- config->importTable = true;
+ ctx.arg.importTable = true;
} else {
// Default table base. Defaults to 1, reserving 0 for the NULL function
// pointer.
- if (!config->tableBase)
- config->tableBase = 1;
+ if (!ctx.arg.tableBase)
+ ctx.arg.tableBase = 1;
// The default offset for static/global data, for when --global-base is
// not specified on the command line. The precise value of 1024 is
// somewhat arbitrary, and pre-dates wasm-ld (Its the value that
// emscripten used prior to wasm-ld).
- if (!config->globalBase && !config->relocatable && !config->stackFirst)
- config->globalBase = 1024;
+ if (!ctx.arg.globalBase && !ctx.arg.relocatable && !ctx.arg.stackFirst)
+ ctx.arg.globalBase = 1024;
}
- if (config->relocatable) {
- if (config->exportTable)
+ if (ctx.arg.relocatable) {
+ if (ctx.arg.exportTable)
error("--relocatable is incompatible with --export-table");
- if (config->growableTable)
+ if (ctx.arg.growableTable)
error("--relocatable is incompatible with --growable-table");
// Ignore any --import-table, as it's redundant.
- config->importTable = true;
+ ctx.arg.importTable = true;
}
- if (config->shared) {
- if (config->memoryExport.has_value()) {
+ if (ctx.arg.shared) {
+ if (ctx.arg.memoryExport.has_value()) {
error("--export-memory is incompatible with --shared");
}
- if (!config->memoryImport.has_value()) {
- config->memoryImport =
- std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
+ if (!ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryImport = std::pair<llvm::StringRef, llvm::StringRef>(
+ defaultModule, memoryName);
}
}
// If neither export-memory nor import-memory is specified, default to
// exporting memory under its default name.
- if (!config->memoryExport.has_value() && !config->memoryImport.has_value()) {
- config->memoryExport = memoryName;
+ if (!ctx.arg.memoryExport.has_value() && !ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryExport = memoryName;
}
}
// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
static void checkOptions(opt::InputArgList &args) {
- if (!config->stripDebug && !config->stripAll && config->compressRelocations)
+ if (!ctx.arg.stripDebug && !ctx.arg.stripAll && ctx.arg.compressRelocations)
error("--compress-relocations is incompatible with output debug"
" information. Please pass --strip-debug or --strip-all");
- if (config->ltoPartitions == 0)
+ if (ctx.arg.ltoPartitions == 0)
error("--lto-partitions: number of threads must be > 0");
- if (!get_threadpool_strategy(config->thinLTOJobs))
- error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs);
+ if (!get_threadpool_strategy(ctx.arg.thinLTOJobs))
+ error("--thinlto-jobs: invalid job count: " + ctx.arg.thinLTOJobs);
- if (config->pie && config->shared)
+ if (ctx.arg.pie && ctx.arg.shared)
error("-shared and -pie may not be used together");
- if (config->outputFile.empty() && !config->thinLTOIndexOnly)
+ if (ctx.arg.outputFile.empty() && !ctx.arg.thinLTOIndexOnly)
error("no output file specified");
- if (config->importTable && config->exportTable)
+ if (ctx.arg.importTable && ctx.arg.exportTable)
error("--import-table and --export-table may not be used together");
- if (config->relocatable) {
- if (!config->entry.empty())
+ if (ctx.arg.relocatable) {
+ if (!ctx.arg.entry.empty())
error("entry point specified for relocatable output file");
- if (config->gcSections)
+ if (ctx.arg.gcSections)
error("-r and --gc-sections may not be used together");
- if (config->compressRelocations)
+ if (ctx.arg.compressRelocations)
error("-r -and --compress-relocations may not be used together");
if (args.hasArg(OPT_undefined))
error("-r -and --undefined may not be used together");
- if (config->pie)
+ if (ctx.arg.pie)
error("-r and -pie may not be used together");
- if (config->sharedMemory)
+ if (ctx.arg.sharedMemory)
error("-r and --shared-memory may not be used together");
- if (config->globalBase)
+ if (ctx.arg.globalBase)
error("-r and --global-base may not by used together...
[truncated]
|
|
@llvm/pr-subscribers-lld-wasm Author: Fangrui Song (MaskRay) ChangesPatch is 87.53 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119835.diff 17 Files Affected:
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 02471950fb5196..7b56bf90af3c1c 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -48,7 +48,7 @@ ConfigWrapper config;
Ctx ctx;
void errorOrWarn(const llvm::Twine &msg) {
- if (config->noinhibitExec)
+ if (ctx.arg.noinhibitExec)
warn(msg);
else
error(msg);
@@ -268,7 +268,7 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
static void readImportFile(StringRef filename) {
if (std::optional<MemoryBufferRef> buf = readFile(filename))
for (StringRef sym : args::getLines(*buf))
- config->allowUndefinedSymbols.insert(sym);
+ ctx.arg.allowUndefinedSymbols.insert(sym);
}
// Returns slices of MB by parsing MB as an archive file.
@@ -345,7 +345,7 @@ void LinkerDriver::addFile(StringRef path) {
case file_magic::bitcode:
case file_magic::wasm_object: {
auto obj = createObjectFile(mbref, "", 0, inLib);
- if (config->isStatic && isa<SharedFile>(obj)) {
+ if (ctx.arg.isStatic && isa<SharedFile>(obj)) {
error("attempted static link of dynamic object " + path);
break;
}
@@ -364,7 +364,7 @@ void LinkerDriver::addFile(StringRef path) {
}
static std::optional<std::string> findFromSearchPaths(StringRef path) {
- for (StringRef dir : config->searchPaths)
+ for (StringRef dir : ctx.arg.searchPaths)
if (std::optional<std::string> s = findFile(dir, path))
return s;
return std::nullopt;
@@ -373,8 +373,8 @@ static std::optional<std::string> findFromSearchPaths(StringRef path) {
// This is for -l<basename>. We'll look for lib<basename>.a from
// search paths.
static std::optional<std::string> searchLibraryBaseName(StringRef name) {
- for (StringRef dir : config->searchPaths) {
- if (!config->isStatic)
+ for (StringRef dir : ctx.arg.searchPaths) {
+ if (!ctx.arg.isStatic)
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
return s;
if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
@@ -408,10 +408,10 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
addFile(arg->getValue());
break;
case OPT_Bstatic:
- config->isStatic = true;
+ ctx.arg.isStatic = true;
break;
case OPT_Bdynamic:
- config->isStatic = false;
+ ctx.arg.isStatic = false;
break;
case OPT_whole_archive:
inWholeArchive = true;
@@ -527,99 +527,98 @@ getBuildId(opt::InputArgList &args) {
// Initializes Config members by the command line options.
static void readConfigs(opt::InputArgList &args) {
- config->allowMultipleDefinition =
+ ctx.arg.allowMultipleDefinition =
hasZOption(args, "muldefs") ||
args.hasFlag(OPT_allow_multiple_definition,
OPT_no_allow_multiple_definition, false);
- config->bsymbolic = args.hasArg(OPT_Bsymbolic);
- config->checkFeatures =
+ ctx.arg.bsymbolic = args.hasArg(OPT_Bsymbolic);
+ ctx.arg.checkFeatures =
args.hasFlag(OPT_check_features, OPT_no_check_features, true);
- config->compressRelocations = args.hasArg(OPT_compress_relocations);
- config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
- config->disableVerify = args.hasArg(OPT_disable_verify);
- config->emitRelocs = args.hasArg(OPT_emit_relocs);
- config->experimentalPic = args.hasArg(OPT_experimental_pic);
- config->entry = getEntry(args);
- config->exportAll = args.hasArg(OPT_export_all);
- config->exportTable = args.hasArg(OPT_export_table);
- config->growableTable = args.hasArg(OPT_growable_table);
- config->noinhibitExec = args.hasArg(OPT_noinhibit_exec);
+ ctx.arg.compressRelocations = args.hasArg(OPT_compress_relocations);
+ ctx.arg.demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
+ ctx.arg.disableVerify = args.hasArg(OPT_disable_verify);
+ ctx.arg.emitRelocs = args.hasArg(OPT_emit_relocs);
+ ctx.arg.experimentalPic = args.hasArg(OPT_experimental_pic);
+ ctx.arg.entry = getEntry(args);
+ ctx.arg.exportAll = args.hasArg(OPT_export_all);
+ ctx.arg.exportTable = args.hasArg(OPT_export_table);
+ ctx.arg.growableTable = args.hasArg(OPT_growable_table);
+ ctx.arg.noinhibitExec = args.hasArg(OPT_noinhibit_exec);
if (args.hasArg(OPT_import_memory_with_name)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
args.getLastArgValue(OPT_import_memory_with_name).split(",");
} else if (args.hasArg(OPT_import_memory)) {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
} else {
- config->memoryImport =
+ ctx.arg.memoryImport =
std::optional<std::pair<llvm::StringRef, llvm::StringRef>>();
}
if (args.hasArg(OPT_export_memory_with_name)) {
- config->memoryExport =
- args.getLastArgValue(OPT_export_memory_with_name);
+ ctx.arg.memoryExport = args.getLastArgValue(OPT_export_memory_with_name);
} else if (args.hasArg(OPT_export_memory)) {
- config->memoryExport = memoryName;
+ ctx.arg.memoryExport = memoryName;
} else {
- config->memoryExport = std::optional<llvm::StringRef>();
+ ctx.arg.memoryExport = std::optional<llvm::StringRef>();
}
- config->sharedMemory = args.hasArg(OPT_shared_memory);
- config->soName = args.getLastArgValue(OPT_soname);
- config->importTable = args.hasArg(OPT_import_table);
- config->importUndefined = args.hasArg(OPT_import_undefined);
- config->ltoo = args::getInteger(args, OPT_lto_O, 2);
- if (config->ltoo > 3)
- error("invalid optimization level for LTO: " + Twine(config->ltoo));
+ ctx.arg.sharedMemory = args.hasArg(OPT_shared_memory);
+ ctx.arg.soName = args.getLastArgValue(OPT_soname);
+ ctx.arg.importTable = args.hasArg(OPT_import_table);
+ ctx.arg.importUndefined = args.hasArg(OPT_import_undefined);
+ ctx.arg.ltoo = args::getInteger(args, OPT_lto_O, 2);
+ if (ctx.arg.ltoo > 3)
+ error("invalid optimization level for LTO: " + Twine(ctx.arg.ltoo));
unsigned ltoCgo =
- args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo));
+ args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(ctx.arg.ltoo));
if (auto level = CodeGenOpt::getLevel(ltoCgo))
- config->ltoCgo = *level;
+ ctx.arg.ltoCgo = *level;
else
error("invalid codegen optimization level for LTO: " + Twine(ltoCgo));
- config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
- config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
- config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
- config->mapFile = args.getLastArgValue(OPT_Map);
- config->optimize = args::getInteger(args, OPT_O, 1);
- config->outputFile = args.getLastArgValue(OPT_o);
- config->relocatable = args.hasArg(OPT_relocatable);
- config->gcSections =
- args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !config->relocatable);
+ ctx.arg.ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
+ ctx.arg.ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
+ ctx.arg.ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+ ctx.arg.mapFile = args.getLastArgValue(OPT_Map);
+ ctx.arg.optimize = args::getInteger(args, OPT_O, 1);
+ ctx.arg.outputFile = args.getLastArgValue(OPT_o);
+ ctx.arg.relocatable = args.hasArg(OPT_relocatable);
+ ctx.arg.gcSections =
+ args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !ctx.arg.relocatable);
for (auto *arg : args.filtered(OPT_keep_section))
- config->keepSections.insert(arg->getValue());
- config->mergeDataSegments =
+ ctx.arg.keepSections.insert(arg->getValue());
+ ctx.arg.mergeDataSegments =
args.hasFlag(OPT_merge_data_segments, OPT_no_merge_data_segments,
- !config->relocatable);
- config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
- config->printGcSections =
+ !ctx.arg.relocatable);
+ ctx.arg.pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
+ ctx.arg.printGcSections =
args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
- config->saveTemps = args.hasArg(OPT_save_temps);
- config->searchPaths = args::getStrings(args, OPT_library_path);
- config->shared = args.hasArg(OPT_shared);
- config->shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
- config->stripAll = args.hasArg(OPT_strip_all);
- config->stripDebug = args.hasArg(OPT_strip_debug);
- config->stackFirst = args.hasArg(OPT_stack_first);
- config->trace = args.hasArg(OPT_trace);
- config->thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
- config->thinLTOCachePolicy = CHECK(
+ ctx.arg.saveTemps = args.hasArg(OPT_save_temps);
+ ctx.arg.searchPaths = args::getStrings(args, OPT_library_path);
+ ctx.arg.shared = args.hasArg(OPT_shared);
+ ctx.arg.shlibSigCheck = !args.hasArg(OPT_no_shlib_sigcheck);
+ ctx.arg.stripAll = args.hasArg(OPT_strip_all);
+ ctx.arg.stripDebug = args.hasArg(OPT_strip_debug);
+ ctx.arg.stackFirst = args.hasArg(OPT_stack_first);
+ ctx.arg.trace = args.hasArg(OPT_trace);
+ ctx.arg.thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
+ ctx.arg.thinLTOCachePolicy = CHECK(
parseCachePruningPolicy(args.getLastArgValue(OPT_thinlto_cache_policy)),
"--thinlto-cache-policy: invalid cache policy");
- config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
- config->thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
+ ctx.arg.thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
+ ctx.arg.thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) ||
args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
+ ctx.arg.thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
args.hasArg(OPT_thinlto_index_only_eq);
- config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
- config->thinLTOObjectSuffixReplace =
+ ctx.arg.thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
+ ctx.arg.thinLTOObjectSuffixReplace =
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
- std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
- config->thinLTOPrefixReplaceNativeObject) =
+ std::tie(ctx.arg.thinLTOPrefixReplaceOld, ctx.arg.thinLTOPrefixReplaceNew,
+ ctx.arg.thinLTOPrefixReplaceNativeObject) =
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace_eq);
- if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) {
+ if (ctx.arg.thinLTOEmitIndexFiles && !ctx.arg.thinLTOIndexOnly) {
if (args.hasArg(OPT_thinlto_object_suffix_replace_eq))
error("--thinlto-object-suffix-replace is not supported with "
"--thinlto-emit-index-files");
@@ -627,45 +626,45 @@ static void readConfigs(opt::InputArgList &args) {
error("--thinlto-prefix-replace is not supported with "
"--thinlto-emit-index-files");
}
- if (!config->thinLTOPrefixReplaceNativeObject.empty() &&
- config->thinLTOIndexOnlyArg.empty()) {
+ if (!ctx.arg.thinLTOPrefixReplaceNativeObject.empty() &&
+ ctx.arg.thinLTOIndexOnlyArg.empty()) {
error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with "
"--thinlto-index-only=");
}
- config->unresolvedSymbols = getUnresolvedSymbolPolicy(args);
- config->whyExtract = args.getLastArgValue(OPT_why_extract);
+ ctx.arg.unresolvedSymbols = getUnresolvedSymbolPolicy(args);
+ ctx.arg.whyExtract = args.getLastArgValue(OPT_why_extract);
errorHandler().verbose = args.hasArg(OPT_verbose);
LLVM_DEBUG(errorHandler().verbose = true);
- config->tableBase = args::getInteger(args, OPT_table_base, 0);
- config->globalBase = args::getInteger(args, OPT_global_base, 0);
- config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
- config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
- config->maxMemory = args::getInteger(args, OPT_max_memory, 0);
- config->noGrowableMemory = args.hasArg(OPT_no_growable_memory);
- config->zStackSize =
+ ctx.arg.tableBase = args::getInteger(args, OPT_table_base, 0);
+ ctx.arg.globalBase = args::getInteger(args, OPT_global_base, 0);
+ ctx.arg.initialHeap = args::getInteger(args, OPT_initial_heap, 0);
+ ctx.arg.initialMemory = args::getInteger(args, OPT_initial_memory, 0);
+ ctx.arg.maxMemory = args::getInteger(args, OPT_max_memory, 0);
+ ctx.arg.noGrowableMemory = args.hasArg(OPT_no_growable_memory);
+ ctx.arg.zStackSize =
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);
// -Bdynamic by default if -pie or -shared is specified.
- if (config->pie || config->shared)
- config->isStatic = false;
+ if (ctx.arg.pie || ctx.arg.shared)
+ ctx.arg.isStatic = false;
- if (config->maxMemory != 0 && config->noGrowableMemory) {
+ if (ctx.arg.maxMemory != 0 && ctx.arg.noGrowableMemory) {
// Erroring out here is simpler than defining precedence rules.
error("--max-memory is incompatible with --no-growable-memory");
}
// Default value of exportDynamic depends on `-shared`
- config->exportDynamic =
- args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, config->shared);
+ ctx.arg.exportDynamic =
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, ctx.arg.shared);
// Parse wasm32/64.
if (auto *arg = args.getLastArg(OPT_m)) {
StringRef s = arg->getValue();
if (s == "wasm32")
- config->is64 = false;
+ ctx.arg.is64 = false;
else if (s == "wasm64")
- config->is64 = true;
+ ctx.arg.is64 = true;
else
error("invalid target architecture: " + s);
}
@@ -679,36 +678,36 @@ static void readConfigs(opt::InputArgList &args) {
error(arg->getSpelling() + ": expected a positive integer, but got '" +
arg->getValue() + "'");
parallel::strategy = hardware_concurrency(threads);
- config->thinLTOJobs = v;
+ ctx.arg.thinLTOJobs = v;
}
if (auto *arg = args.getLastArg(OPT_thinlto_jobs))
- config->thinLTOJobs = arg->getValue();
+ ctx.arg.thinLTOJobs = arg->getValue();
if (auto *arg = args.getLastArg(OPT_features)) {
- config->features =
+ ctx.arg.features =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->features->push_back(std::string(s));
+ ctx.arg.features->push_back(std::string(s));
}
if (auto *arg = args.getLastArg(OPT_extra_features)) {
- config->extraFeatures =
+ ctx.arg.extraFeatures =
std::optional<std::vector<std::string>>(std::vector<std::string>());
for (StringRef s : arg->getValues())
- config->extraFeatures->push_back(std::string(s));
+ ctx.arg.extraFeatures->push_back(std::string(s));
}
// Legacy --allow-undefined flag which is equivalent to
// --unresolve-symbols=ignore + --import-undefined
if (args.hasArg(OPT_allow_undefined)) {
- config->importUndefined = true;
- config->unresolvedSymbols = UnresolvedPolicy::Ignore;
+ ctx.arg.importUndefined = true;
+ ctx.arg.unresolvedSymbols = UnresolvedPolicy::Ignore;
}
if (args.hasArg(OPT_print_map))
- config->mapFile = "-";
+ ctx.arg.mapFile = "-";
- std::tie(config->buildId, config->buildIdVector) = getBuildId(args);
+ std::tie(ctx.arg.buildId, ctx.arg.buildIdVector) = getBuildId(args);
}
// Some Config members do not directly correspond to any particular
@@ -716,86 +715,86 @@ static void readConfigs(opt::InputArgList &args) {
// This function initialize such members. See Config.h for the details
// of these values.
static void setConfigs() {
- ctx.isPic = config->pie || config->shared;
+ ctx.isPic = ctx.arg.pie || ctx.arg.shared;
if (ctx.isPic) {
- if (config->exportTable)
+ if (ctx.arg.exportTable)
error("-shared/-pie is incompatible with --export-table");
- config->importTable = true;
+ ctx.arg.importTable = true;
} else {
// Default table base. Defaults to 1, reserving 0 for the NULL function
// pointer.
- if (!config->tableBase)
- config->tableBase = 1;
+ if (!ctx.arg.tableBase)
+ ctx.arg.tableBase = 1;
// The default offset for static/global data, for when --global-base is
// not specified on the command line. The precise value of 1024 is
// somewhat arbitrary, and pre-dates wasm-ld (Its the value that
// emscripten used prior to wasm-ld).
- if (!config->globalBase && !config->relocatable && !config->stackFirst)
- config->globalBase = 1024;
+ if (!ctx.arg.globalBase && !ctx.arg.relocatable && !ctx.arg.stackFirst)
+ ctx.arg.globalBase = 1024;
}
- if (config->relocatable) {
- if (config->exportTable)
+ if (ctx.arg.relocatable) {
+ if (ctx.arg.exportTable)
error("--relocatable is incompatible with --export-table");
- if (config->growableTable)
+ if (ctx.arg.growableTable)
error("--relocatable is incompatible with --growable-table");
// Ignore any --import-table, as it's redundant.
- config->importTable = true;
+ ctx.arg.importTable = true;
}
- if (config->shared) {
- if (config->memoryExport.has_value()) {
+ if (ctx.arg.shared) {
+ if (ctx.arg.memoryExport.has_value()) {
error("--export-memory is incompatible with --shared");
}
- if (!config->memoryImport.has_value()) {
- config->memoryImport =
- std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
+ if (!ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryImport = std::pair<llvm::StringRef, llvm::StringRef>(
+ defaultModule, memoryName);
}
}
// If neither export-memory nor import-memory is specified, default to
// exporting memory under its default name.
- if (!config->memoryExport.has_value() && !config->memoryImport.has_value()) {
- config->memoryExport = memoryName;
+ if (!ctx.arg.memoryExport.has_value() && !ctx.arg.memoryImport.has_value()) {
+ ctx.arg.memoryExport = memoryName;
}
}
// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
static void checkOptions(opt::InputArgList &args) {
- if (!config->stripDebug && !config->stripAll && config->compressRelocations)
+ if (!ctx.arg.stripDebug && !ctx.arg.stripAll && ctx.arg.compressRelocations)
error("--compress-relocations is incompatible with output debug"
" information. Please pass --strip-debug or --strip-all");
- if (config->ltoPartitions == 0)
+ if (ctx.arg.ltoPartitions == 0)
error("--lto-partitions: number of threads must be > 0");
- if (!get_threadpool_strategy(config->thinLTOJobs))
- error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs);
+ if (!get_threadpool_strategy(ctx.arg.thinLTOJobs))
+ error("--thinlto-jobs: invalid job count: " + ctx.arg.thinLTOJobs);
- if (config->pie && config->shared)
+ if (ctx.arg.pie && ctx.arg.shared)
error("-shared and -pie may not be used together");
- if (config->outputFile.empty() && !config->thinLTOIndexOnly)
+ if (ctx.arg.outputFile.empty() && !ctx.arg.thinLTOIndexOnly)
error("no output file specified");
- if (config->importTable && config->exportTable)
+ if (ctx.arg.importTable && ctx.arg.exportTable)
error("--import-table and --export-table may not be used together");
- if (config->relocatable) {
- if (!config->entry.empty())
+ if (ctx.arg.relocatable) {
+ if (!ctx.arg.entry.empty())
error("entry point specified for relocatable output file");
- if (config->gcSections)
+ if (ctx.arg.gcSections)
error("-r and --gc-sections may not be used together");
- if (config->compressRelocations)
+ if (ctx.arg.compressRelocations)
error("-r -and --compress-relocations may not be used together");
if (args.hasArg(OPT_undefined))
error("-r -and --undefined may not be used together");
- if (config->pie)
+ if (ctx.arg.pie)
error("-r and -pie may not be used together");
- if (config->sharedMemory)
+ if (ctx.arg.sharedMemory)
error("-r and --shared-memory may not be used together");
- if (config->globalBase)
+ if (ctx.arg.globalBase)
error("-r and --global-base may not by used together...
[truncated]
|
sbc100
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a little context to the PR description? i.e. Why is this better?
Does this change also remove the old config global or just stop using it?
Objectively this still like a regression in readability since it adds more visual noise and indirection. However, I get that we are trying to make lld more library-friendly. I'm just a little sad that it comes are this readability cost :(
Created using spr 1.3.5-bogner [skip ci]
|
Updated the description. This consolidates global variables. |
|
Ping:) |
|
|
||
| namespace lld::wasm { | ||
| ConfigWrapper config; | ||
| Ctx ctx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the global config on line 47, or is that for a followup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed ConfigWrapper config. Yes, that was intended to be a follow-up, but it seems easy to fold it into this PR.
sbc100
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % comment
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner
Created using spr 1.3.5-bogner [skip ci]
Change the global variable reference to a member access of another variable `ctx`. In the future, we may pass through `ctx` to functions to eliminate global variables. Pull Request: llvm/llvm-project#119835
Change the global variable reference to a member access of another
variable
ctx. In the future, we may pass throughctxto functions toeliminate global variables.